package com.weiyi.session;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/user.view")
public class User extends HttpServlet{
	
	protected void proccessResquest(HttpServletRequest req,HttpServletResponse resp) throws IOException {
		resp.setContentType("text/html;charset=UTF-8");
		if(req.getAttribute("username") == null) {
			resp.sendRedirect("login.html");
		}
		PrintWriter out = resp.getWriter();
		out.println("<!DOCTYPE html PUBLIC "+
				"'-//W3C//DTD HTML 4.01 Transitional//EN'>");
		out.println("<html>");
		out.println("<head>");
		out.println("<meta content='text/html;charset=UTF-8'"+
		"http-equiv='content-type'>");
		out.println("<titlt>Servlet User</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<h1>"+req.getAttribute("username")+"已登录</h1>");
		out.println("</body>");
		out.println("</html>");
		out.close();
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		proccessResquest(req,resp);
	
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		proccessResquest(req,resp);
	
	}
	
	
}
